<%@ Page Language="VB" MasterPageFile="../PageTemplate.master" MaintainScrollPositionOnPostback="true" Title="Content Page 1" AutoEventWireup="false" CodeFile="Purchases.aspx.vb" Inherits="HardwareKeys" %>

<asp:Content ID="Content2" ContentPlaceHolderID="HeaderContent" Runat="Server">
<div style="width:60%">
    History of clicks purchased database<br />User name: <asp:Label id="HeaderLabel1" runat="server" /><br />
    Client name: <asp:Label id="HeaderLabel2" runat="server" /><br />
 </div>
</asp:Content>

<asp:Content id="Content3" ContentPlaceHolderID="dividing_line" runat="server">
    <img src="../images/hline_green.gif" width="100%" />
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <br />
 
        <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" CellPadding="5"
            DataSourceID="SqlDataSource1" DefaultMode="Insert" Visible="False" Height="303px">
            <Fields>
            
                <asp:TemplateField HeaderText="Date">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox ID="purchasedate_txtbox1" runat="server" Width="160px" Text='<%# Bind("DatePurchased","{0:dd/MM/yyyy}") %>' />
                        <asp:RegularExpressionValidator ID="RegExpValidator1" runat="server" ControlToValidate="purchasedate_txtbox1"
                            ErrorMessage="You must enter a valid date not more than 50 years away" ForeColor="yellowgreen"
                            ValidationExpression="^((([0]?[1-9]|[12]\d)[.\\/-]([0]?\d|1[012]))|(30[.\\/-]([0]?[469]|11))|((3[0|1])[.\\/-]([0]?[13578]|1[02])))[.\\/-]((19|20)([0-9]{2})|[0-9]{2})$"></asp:RegularExpressionValidator>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="PCName">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox ID="PCName_txtbox1" runat="server" Rows="1"  Width="240px"
                            Wrap="true" Text='<%# Bind("PCName") %>' />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="HardwareKey">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox ID="HardwareKey_txtbox1" runat="server" Rows="1"  Width="240px"
                            Wrap="true" Text='<%# Bind("HardwareKey") %>' />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                
                
                <asp:TemplateField HeaderText="Clicks bought">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox ID="clickspurchased_txtbox1" runat="server" Width="160px" Text='<%# Bind("ClicksPurchased") %>' />
                        <asp:RangeValidator ID="RangeValidator1" runat="server" ControlToValidate="clickspurchased_txtbox1"
                            ErrorMessage="You must enter a number between 0 and 10,000,000" ForeColor="yellowgreen"
                            MaximumValue="10000000" MinimumValue="0" Type="Integer"></asp:RangeValidator>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Expiry">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox ID="expirydate_txtbox1" runat="server" Width="160px" Text='<%# Bind("ExpiryDate","{0:dd/MM/yyyy}") %>' />
                        <asp:RegularExpressionValidator ID="RegExpValidator2" runat="server" ControlToValidate="expirydate_txtbox1"
                            ErrorMessage="You must enter a valid date not more than 50 years away" ForeColor="yellowgreen"
                            ValidationExpression="^((([0]?[1-9]|[12]\d)[.\\/-]([0]?\d|1[012]))|(30[.\\/-]([0]?[469]|11))|((3[0|1])[.\\/-]([0]?[13578]|1[02])))[.\\/-]((19|20)([0-9]{2})|[0-9]{2})$"></asp:RegularExpressionValidator>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Unlimited">
                    <ItemTemplate>
                        <asp:checkbox ID="unlimitedclicks_txtbox1" runat="server" Checked='<%# Bind("UnlimitedClicks") %>' />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Type">
                    <ItemTemplate>
                        &nbsp;
                        <asp:ListBox runat="server" ID="type_txtbox1"  Text='<%# Bind("Type") %>' Rows="5" > 
                            <asp:ListItem Value="0">Road level</asp:ListItem>
                            <asp:ListItem Value="1">Premise level</asp:ListItem>
                            <asp:ListItem Value="2">Map ref</asp:ListItem>
                            <asp:ListItem Value="3">Place list</asp:ListItem>
                            <asp:ListItem Value="4">Street list</asp:ListItem>
                        </asp:ListBox>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Areas">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox ID="areas_txtbox1" runat="server" Rows="3" TextMode="MultiLine" Width="240px"
                            Wrap="true" Text='<%# Bind("Areas") %>' />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                
                
                <asp:TemplateField HeaderText="Notify">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox ID="notify_txtbox1" runat="server" Width="160px"
                            Wrap="true" Text='<%# Bind("Notify") %>' />
                        <asp:RangeValidator ID="RangeValidator2" runat="server" ControlToValidate="notify_txtbox1"
                            ErrorMessage="You must enter a number between 0 and 10,000,000" ForeColor="yellowgreen"
                            MaximumValue="10000000" MinimumValue="0" Type="Integer"></asp:RangeValidator>
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Comments">
                    <ItemTemplate>
                        &nbsp;
                        <asp:TextBox ID="comments_txtbox1" runat="server" Rows="5" TextMode="MultiLine" Width="160px"
                            Wrap="true" Text='<%# Bind("Comments") %>' />
                    </ItemTemplate>
                    <ItemStyle HorizontalAlign="Left" />
                </asp:TemplateField>
                                
            </Fields>
            <FooterTemplate>
                <asp:Button ID="myInsertButton" runat="server" CommandName="Insert" Text="Generate" />
                <asp:Button ID="myCancelButton" runat="server" CausesValidation="false" CommandName="Cancel"
                    Text="Cancel" />
            </FooterTemplate>
        </asp:DetailsView>          
        
        <asp:Button ID="Add_Purchase_Button2" runat="server" Height="35px" Text="Add a block of clicks" Width="169px" />

        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID"
            DataSourceID="SqlDataSource1"  HeaderStyle-Height="50px">
            <Columns>

                <asp:CommandField HeaderText="Edit" EditText="Edit..." ShowEditButton="True" />
                <asp:BoundField DataField="ID" HeaderText="ID" SortExpression="ID"  Visible="False" ReadOnly="True"/>     
                <asp:BoundField DataField="UserID" HeaderText="UserID" SortExpression="UserID"  Visible="False" ReadOnly="True"/>     

                <asp:TemplateField HeaderText="Date" SortExpression="DatePurchased">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="DatePurchased_label" Text='<%# Split("" & Eval("DatePurchased","{0:dd/MM/yyyy}" ))(0) %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" Width="100px" ID="DatePurchased_textbox" Text='<%# Split("" & Eval("DatePurchased","{0:dd/MM/yyyy}" ))(0) %>' 
                        /> 
                    </EditItemTemplate>
                </asp:TemplateField>
                
                                
                <asp:TemplateField HeaderText="PC name" SortExpression="PCName"  ItemStyle-Width="20px">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="PCName_label" Text='<%# Bind("PCName") %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" ID="PCName_textbox" Text='<%# Bind("PCName") %>' /> 
                    </EditItemTemplate>
                </asp:TemplateField>
                
                                
                <asp:TemplateField HeaderText="Hardware key" SortExpression="HardwareKey"  ItemStyle-Width="20px">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="HardwareKey_label" Text='<%# Bind("HardwareKey") %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" ID="HardwareKey_textbox" Text='<%# Bind("HardwareKey") %>' /> 
                    </EditItemTemplate>
                </asp:TemplateField>
                

                <asp:TemplateField HeaderText="Clicks bought" SortExpression="ClicksPurchased" ItemStyle-Width="20px">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="ClicksPurchased_label" Text='<%# Bind("ClicksPurchased") %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" ID="ClicksPurchased_textbox" Text='<%# Bind("ClicksPurchased") %>' /> 
                    </EditItemTemplate>
                </asp:TemplateField>

                <asp:BoundField DataField="ClicksUsed" HeaderText="Clicks used" SortExpression="ClicksUsed" ReadOnly="true" ItemStyle-Width="20px" />

                <asp:TemplateField HeaderText="Expiry" SortExpression="ExpiryDate">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="ExpiryDate_label" Text='<%# Split("" & Eval("ExpiryDate","{0:dd/MM/yyyy}" ))(0) %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server"  ID="ExpiryDate_textbox" Text='<%# Split("" & Eval("ExpiryDate","{0:dd/MM/yyyy}"))(0) %>' 
                        /> 
                    </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Unlimited" >
                    <ItemTemplate>
                        <asp:Label runat="server" ID="UnlimitedClicks_label" Text='<%# YesNo( eval("UnlimitedClicks") ) %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:HiddenField runat="server" ID="ID_field" Value='<%# Bind("ID") %>'
                             />
                        <asp:CheckBox runat="server" ID="UnlimitedClicks_checkbox" Checked='<%# Bind("UnlimitedClicks") %>' /> 
                    </EditItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Type" >
                    <ItemTemplate>
                        <asp:Label runat="server" ID="Type_label" Text='<%# type_evaluator( eval("Type") ) %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:ListBox runat="server" ID="Type_listbox"  Text='<%# Bind("Type") %>' Rows="5" > 
                            <asp:ListItem Value="0">Road level</asp:ListItem>
                            <asp:ListItem Value="1">Premise level</asp:ListItem>
                            <asp:ListItem Value="2">Map ref</asp:ListItem>
                            <asp:ListItem Value="3">Place list</asp:ListItem>
                            <asp:ListItem Value="4">Street list</asp:ListItem>
                        </asp:ListBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Areas" SortExpression="Areas">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="Areas_label" Text='<%# left("" & eval("Areas"),30) %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" ID="Areas_textbox" Text='<%# Bind("Areas") %>' 
                            TextMode="multiline" Rows="3" Wrap="true" /> 
                    </EditItemTemplate>
                </asp:TemplateField>
                
                
                
                <asp:TemplateField HeaderText="Notify" SortExpression="Notify">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="Notify_label" Text='<%# Bind("Notify") %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" Width="70px" ID="Notify_textbox" Text='<%# Bind("Notify") %>' /> 
                    </EditItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Comments" SortExpression="Comments">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="Comments_label" Text='<%# left("" & eval("Comments"),30) %>'
                            SkinID="normal" />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox runat="server" ID="Comments_textbox" Text='<%# Bind("Comments") %>' 
                            TextMode="multiline" Rows="4" Wrap="true" /> 
                    </EditItemTemplate>
                </asp:TemplateField>
                
                <asp:TemplateField HeaderText="Delete">
                 <ItemTemplate>
                   <asp:LinkButton ID="LinkButton1" 
                     CommandArgument='<%# Eval("ID") %>' 
                     CommandName="Delete" runat="server">
                     Delete...</asp:LinkButton>
                 </ItemTemplate>
               </asp:TemplateField>
   
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LocalConnectionString %>"
            ProviderName="<%$ ConnectionStrings:LocalConnectionString.ProviderName %>"
            SelectCommand="SELECT ID, UserID, PCName, HardwareKey, DatePurchased, ClicksPurchased, ExpiryDate, Areas,Comments,[Type],ClicksUsed,UnlimitedClicks,Notify FROM History WHERE UserID=@IDKey_Foreign ORDER BY DatePurchased DESC" 
            DeleteCommand="DELETE FROM History WHERE ID=@ID" 
            >
            
            <SelectParameters>
                <asp:QueryStringParameter QueryStringField="ID" Name="IDKey_Foreign" DefaultValue="" Type="String" />
            </SelectParameters>
            <UpdateParameters>
                <asp:Parameter Name="DatePurchased" Type="DateTime" />
                <asp:Parameter Name="ClicksPurchased" Type="Int32" />
                <asp:Parameter Name="ExpiryDate" Type="DateTime" />
                <asp:Parameter Name="UnlimitedClicks" Type="Boolean" />
                <asp:Parameter Name="Comments" Type="String" Size="255" />
                <asp:Parameter Name="PCName" Type="String" Size="255" />
                <asp:Parameter Name="HardwareKey" Type="String" Size="255" />
                <asp:Parameter Name="Areas" Type="String" />
                <asp:Parameter Name="Type" Type="Int32" />
                <asp:Parameter Name="Notify" Type="Int32" />
            </UpdateParameters>
            <%--<InsertParameters>
                <asp:Parameter Name="DatePurchased" Type="DateTime" />
                <asp:Parameter Name="ClicksPurchased" Type="Int32" />
                <asp:Parameter Name="ExpiryDate" Type="DateTime" />
                <asp:Parameter Name="UnlimitedClicks" Type="Boolean" />
                <asp:Parameter Name="PCName" Type="String" Size="255" />
                <asp:Parameter Name="HardwareKey" Type="String" Size="255" />
                <asp:Parameter Name="Type" Type="Int32" />
                <asp:Parameter Name="Notify" Type="Int32" />
                <asp:Parameter Name="Areas" Type="String" />
                <asp:Parameter Name="Comments" Type="String" />
            </InsertParameters>--%>
        </asp:SqlDataSource>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" Text="Back to client clicks database" /><br />
        <br />
    
    </div>
</asp:Content>